package org.example;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 乱序有可能导致线程里的number是默认0,
 * ready = true会在t1.start()之前执行
 */
public class DisorderBug2 {
    private static boolean ready = false;
    private static int number;

    ReentrantLock lock;
    public static void main(String[] args) throws Exception{
        lock.lock();
        lock.unlock();
        Thread t1 = new Thread(()->{
            while (!ready){
                Thread.yield();
            }
            System.out.println(number);
        });

        t1.start();
        number = 11;
        ready = true;
        t1.join();
    }
}
